<?php

namespace iflow\swoole\implement\Server\GRpc;

use iflow\initializer\Error;
use iflow\swoole\implement\Server\Http\Service as HttpService;

class Service extends HttpService {

    protected array $grpcContentType = [
        'application/grpc',
        'application/grpc+proto'
    ];

    public function onRequest(object $request, object $response): void {

        try {
            if (!in_array($request -> header['content-type'], $this->grpcContentType)) {
                throw new \Exception('Invalid then Content-Type');
            }

            parent::onRequest($request, $response); // TODO: Change the autogenerated stub
        } catch (\Throwable $exception) {
            app(Error::class) -> appHandler($exception);
        }
    }


}